/**
 * 系统设置控制器
 */
import $_fn from '~plugins'
export default ['$scope','$rootScope','$location','$ui','http',function($scope,$rootScope,$location,$ui,http) {
    $scope.tabMenu = $_fn.getCurrMenu($location.path())
    console.log($scope.tabMenu)
    $scope.params = {}
    $scope.params = $location.search()
    //初始化对象
    $scope.param={}
    //警告提示
      $scope.errorToast = function(text) {
        $ui.toast({text:text,type:'warning',position:'center',appendTo:'.wp-container'});
      }
      //成功提示
      $scope.successToast = function(text) {
          $ui.toast({text:text,type:'success',position:'center',appendTo:'.wp-container'});
      }
      $scope.remHight = function(){                                                 //去除报错高亮
        for(var i in $scope.redErr){
          $scope.redErr[i] = false
        }
      }
    //分页参数
    $scope.page = {
      current:  1
    }

    //获取数据的函数
    $scope.getDada = function(page,params){
      console.log('$this:', )
        params.pageNum = page
        if(params.paramType1==-1 ||!params.paramType){
          params.paramType = ''
        }else if(params.paramType1==1){
          params.paramType = 'position'

        }else if(params.paramType1==2){
          params.paramType = 'applyTerm'

        }else if(params.paramType1==3){
          params.paramType = 'educationLevel'
        }
        http.post('paramSet.do', params, function (data) {
            let _data = data.data
            // $scope.page.pageNum =  $scope.page.current
            // $scope.page.pageSize = _data.pageSize
            // $scope.page.total = _data.total
            if(data.errcode > 0){
              //列表无数据
              console.log('log:', data, _data.list)
              $scope.$apply(function () {
                $scope.dataList = _data
              })
            }
        })
    }
    //初始化数据
    $scope.getDada(1,$scope.params)
    //搜索
    $scope.searchHandle = function () {
      $location.search($scope.params)
      $scope.getDada(1,$scope.params)
    }
    /**
     * 四级权限菜单
     * state = 1                      地址栏所要显示的菜单
     * path = link@、alert@           link(连接)、alert(弹窗) 例:link@application.intoa(跳转到全部进件列表)
     * */
    $scope.operation = function (path,item) {
        //刷新函数赋给根scope
        $rootScope.refreshPage = $scope.getDada
        var _path = path.split('@')
        console.log('_path:', _path,item)
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1],item,{reload:true})
        }
        if(_path[0] == 'alert'){
          $ui.modal({content:"<"+_path[1]+" params="+params+" ></"+_path[1]+">"})
      }
    }

    //获取当前路由的四级权限
    var menu = $_fn.getLocal('parentMenu')
    $scope.subMenu = []
    var _subMenu = function (path,_menu) {
        for (var a in _menu) {
            if (_menu[a].children) {
                for (var i in _menu[a].children) {
                    if (_menu[a].children[i].path == path) {
                        $scope.subMenu = _menu[a].children[i].children
                        break
                    } else {
                        _subMenu(path,_menu[a].children[i].children)
                    }
                }
            }
        }
    }
    _subMenu('/setup/global',menu.children)
}]
